// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#ifndef __H_MK_BONE__
#define __H_MK_BONE__

#include "mk_scene_node.h"

namespace MK3DE
{
	class CSkeleton;

	class MK3DE_API CBone : public CSceneNode
	{
		friend class CSkeleton;

	public:
		CBone(CSkeleton* pSkeleton, int index);
		~CBone();

		void Update(DWORD dt, CSceneNode* parent, BOOL bChanged, BOOL relative, DWORD start, DWORD end, float factor);

		int GetParentIdx();

		void SetBaseTransform(D3DXMATRIX& mat) { _matBaseTransform = mat; }
		D3DXMATRIX& GetBaseTransform() { return _matBaseTransform; }
		D3DXMATRIX GetLocalTransformFromBase() { return _matBaseTransform * _matLocalTransform; }
		D3DXMATRIX& GetLocalTransformation() { return _matLocalTransform; }

	private:
		void __UpdateTranslation(DWORD start, DWORD end, float factor);
		void __UpdateRotation(DWORD start, DWORD end, float factor);
		void __UpdateScale(DWORD start, DWORD end, float factor);
		void __UpdateScaleRotation(DWORD start, DWORD end, float factor);

	private:
		//! The index of this bone
		int _index;

		//! The pointer of the skeleton which the bone belong to
		CSkeleton* _pSkeleton;

		//! ...
		D3DXMATRIX _matBaseTransform;

		//! Local transformation.
		D3DXMATRIX _matLocalTransform;
	};
};

#endif /* __H_MK_BONE__ */